import java.util.*;

/**
 *
 */
class Person {
    public String id;

    public Person(String id) {
        this.id = id;
    }

    /**
     *
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    /**
     * 找位置
     * @return
     */
    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
public class Test {

    public static void main(String[] args) {

        Person person1 = new Person("1234");
        Person person2 = new Person("1234");
        /*Person person3 = new Person("789");
        Person person4 = new Person("666");
        Person person5 = new Person("458");
        Person person6 = new Person("498");
        Person person7 = new Person("732");
        Person person8 = new Person("699");*/
        //System.out.println(person1.hashCode());
        //System.out.println(person2.hashCode());


        HashBuck<Person,String> hashBuck = new HashBuck<>();
        hashBuck.put(person1,"111");
        hashBuck.put(person2,"222");
        /*hashBuck.put(person3,"333");
        hashBuck.put(person4,"444");
        hashBuck.put(person5,"111");
        hashBuck.put(person6,"222");
        hashBuck.put(person7,"333");
        hashBuck.put(person8,"444");*/



        String name = hashBuck.get(person2);

        System.out.println(name);

    }


    public static void main3(String[] args) {
        HashBucket hashBucket = new HashBucket();
        hashBucket.put(1,11);
        hashBucket.put(2,22);
        hashBucket.put(12,122);
        hashBucket.put(3,33);
        hashBucket.put(4,44);
        hashBucket.put(14,144);
        hashBucket.put(5,55);
        hashBucket.put(6,66);
        hashBucket.put(16,166);
        System.out.println(hashBucket.get(16));
    }

    public int firstUniqChar(String s) {
        int[] countArray = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            countArray[ch - 'a']++;
        }

        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (countArray[ch - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }
    //set当中的元素 是不可以重复的
    public static void main2(String[] args) {
        Set<String> strings = new TreeSet<>();
        strings.add("hello");
        strings.add("abcd");
        strings.add("def");
        strings.add("def");//这里TreeSet底层是TreeMap，每次存储元素放到map的key上
       // System.out.println("fdsaa");
        //strings.clear();

        Iterator<String> it = strings.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }

    }
    public static void main1(String[] args) {
        Map<String, Integer> map = new TreeMap<>();
        map.put("abcde",4);
        map.put("abcdf",5);
        map.put("abcdfg",6);
        map.put("abcdfg",61);//相同的key 会更新val值
        /*System.out.println(map.get("abcde"));
        map.remove("abcde");
        System.out.println(map.get("abcdfg"));
        System.out.println(map.getOrDefault("abcde", 999));*/
        //Set<String> set = map.keySet();
        //Collection<Integer> value = map.values();
        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();

        for (Map.Entry<String, Integer> entry : entrySet) {
            System.out.println("key : " + entry.getKey() + ", " + " value : " + entry.getValue());
        }




        System.out.println("sfsaa");


        System.out.println(map.getOrDefault("abcd",9999));


        System.out.println(map.getOrDefault("abcd",9999));

        System.out.println("sfsaa");

    }
}
